package com.itboye.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.shop.R;
import com.itboye.shop.app.MyApplication;
import com.itboye.shop.bean.BankCodeBean;

import java.util.List;

/**
 *我的账户
 */
public class ZhangHuAdapter  extends BaseAdapter {
    List<BankCodeBean> bean;
    Context context;

    public ZhangHuAdapter(List<BankCodeBean> bean, Context context) {
        this.context = context;
        this.bean = bean;
    }

    @Override
    public int getCount() {
        return bean.size();
    }

    @Override
    public Object getItem(int position) {
        return bean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoudr houdr;
        if (convertView == null) {
            houdr = new ViewHoudr();
            convertView = LayoutInflater.from(MyApplication.instatnce).inflate(R.layout.item_zhnghu, null);
            houdr.card_type = (TextView) convertView.findViewById(R.id.card_type);
            houdr.card_name = (TextView) convertView.findViewById(R.id.card_name);
            houdr.card_code = (TextView) convertView.findViewById(R.id.card_code);
            houdr.card_img = (ImageView) convertView.findViewById(R.id.card_img);
            houdr.linitem = (LinearLayout) convertView.findViewById(R.id.linitem);

            convertView.setTag(houdr);
        } else {
            houdr = (ViewHoudr) convertView.getTag();
        }

        houdr.card_name.setText(bean.get(position).getExtra());
        if (bean.get(position).getAccount_type().equals("6179")) {
            houdr.card_img.setBackgroundResource(R.drawable.zhifubao);
            houdr.linitem.setBackgroundResource(R.drawable.alipay);
        } else {
            // houdr.card_img.setBackgroundResource(R.drawable.yinhangkazhifu);

            String code=bean.get(position).getExtra();//银行卡类型

            if(code.equals("工商银行")){
                houdr.card_img.setBackgroundResource(R.drawable.gongshang_bank);
                houdr.linitem.setBackgroundResource(R.drawable.gongshang_bank_bj);
            }else if(code.equals("北京银行")){
                houdr.card_img.setBackgroundResource(R.drawable.beijing_bank);
                houdr.linitem.setBackgroundResource(R.drawable.beijing_bank_bj);
            }else if(code.equals("广发银行")){
                houdr.card_img.setBackgroundResource(R.drawable.guangzhou_bank);
                houdr.linitem.setBackgroundResource(R.drawable.guangzhou_bank_bj);
            }else if(code.equals("广州农商银行")){
                houdr.card_img.setBackgroundResource(R.drawable.guangzhounongshang_bank);
                houdr.linitem.setBackgroundResource(R.drawable.guangzhounongshang_bank_bj);
            }else if(code.equals("花旗银行")){
                houdr.card_img.setBackgroundResource(R.drawable.huaqi_bank);
                houdr.linitem.setBackgroundResource(R.drawable.huaqi_bank_bj);
            }else if(code.equals("华夏银行")){
                houdr.card_img.setBackgroundResource(R.drawable.huaxia_bank);
                houdr.linitem.setBackgroundResource(R.drawable.huaxia_bank_bj);
            }else if(code.equals("建设银行")){
                houdr.card_img.setBackgroundResource(R.drawable.jianshe_bank);
                houdr.linitem.setBackgroundResource(R.drawable.jianshe_bank_bj);
            }else if(code.equals("交通银行")){
                houdr.card_img.setBackgroundResource(R.drawable.jiaotong_bank);
                houdr.linitem.setBackgroundResource(R.drawable.jiaotong_bank_bj);
            }else if(code.equals("民生银行")){
                houdr.card_img.setBackgroundResource(R.drawable.minsheng_bank);
                houdr.linitem.setBackgroundResource(R.drawable.minsheng_bank_bj);
            }else if(code.equals("农业银行")){
                houdr.card_img.setBackgroundResource(R.drawable.nongye_bankl);
                houdr.linitem.setBackgroundResource(R.drawable.nongye_bankl_bj);
            }else if(code.equals("平安银行")){
                houdr.card_img.setBackgroundResource(R.drawable.pingan_bank);
                houdr.linitem.setBackgroundResource(R.drawable.pingan_bank_bj);
            }else if(code.equals("浦发银行")){
                houdr.card_img.setBackgroundResource(R.drawable.pufa_bank);
                houdr.linitem.setBackgroundResource(R.drawable.pufa_bank_bj);
            }else if(code.equals("深圳发展银行")){
                houdr.card_img.setBackgroundResource(R.drawable.shenzhenfazhan_bank);
                houdr.linitem.setBackgroundResource(R.drawable.shenzhenfazhan_bank_bj);
            }else if(code.equals("兴业银行")){
                houdr.card_img.setBackgroundResource(R.drawable.xingye_bank);
                houdr.linitem.setBackgroundResource(R.drawable.xingye_bank_bj);
            }else if(code.equals("邮政储蓄银行")){
                houdr.card_img.setBackgroundResource(R.drawable.youzheng_bank);
                houdr.linitem.setBackgroundResource(R.drawable.youzheng_bank_bj);
            }else if(code.equals("招商银行")){
                houdr.card_img.setBackgroundResource(R.drawable.zhaoshang_bank);
                houdr.linitem.setBackgroundResource(R.drawable.zhaoshang_bank_bj);
            }else if(code.equals("中国银行")){
                houdr.card_img.setBackgroundResource(R.drawable.zhongguo_bank);
                houdr.linitem.setBackgroundResource(R.drawable.zhongguo_bank_bj);
            }else if(code.equals("中兴银行")){
                houdr.card_img.setBackgroundResource(R.drawable.zhongxin_bank);
                houdr.linitem.setBackgroundResource(R.drawable.bank);
            }else if(code.equals("光大银行")){
                houdr.card_img.setBackgroundResource(R.drawable.guangda_bank);
                houdr.linitem.setBackgroundResource(R.drawable.guangda_bank_bj);
            }else{
                houdr.card_img.setBackgroundResource(R.drawable.zhaoshang_bank);
                houdr.linitem.setBackgroundResource(R.drawable.bank);
            }
        }

        //    houdr.MessgeTitle.setText(bean.get(position).getName());
        String name=bean.get(position).getAccount();//银行卡号
        if(name.length()>4){
            String s=name.substring(name.length()-4, name.length());//后四位
            String ss=name.substring(0, name.length()-4);//后四位
            StringBuffer sb=new StringBuffer();
            for (int i=0;i<ss.length();i++){
                sb.append("*");
            }
            houdr.card_code.setText(sb+s);
        }else{
            houdr.card_code.setText(bean.get(position).getAccount());
        }
        return convertView;
    }

    private class ViewHoudr {
        private TextView card_type;//类型
        private TextView card_name;
        ImageView card_img;
        private TextView card_code;
        LinearLayout linitem;
    }
}
